/*

This file is part of Rooms3D.

Copyright (C) 2008 Pixecur Technologies Incorporated (Esotera).
Visit Esotera at http://www.esoteras3.com
 
Rooms3D is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
 
Rooms3D is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with Rooms3D; see the file COPYING.  If not, write to 
Pixecur Technologies, 213-31 Peet Street, St. John's, NL, A1B 3W8. 
 
Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
 
*/

package com.datasentinel.j3d.controls;

import java.awt.Font;
import java.awt.geom.Rectangle2D;

import javax.media.j3d.Canvas3D;
import javax.media.j3d.Transform3D;
import javax.vecmath.Vector3d;

import com.datasentinel.j3d.utils.geometry.MutableText2D;

public class J3DUIHelper
{

	public static void prepareCenteredText2DTransform(Canvas3D canvas3d, Font font, MutableText2D text2D, Transform3D translateTextT3D, float depth)
	{
		prepareCenteredText2DTransform(canvas3d, font, text2D, translateTextT3D, depth, 1.0f);
	}

	
	public static void prepareCenteredText2DTransform(Canvas3D canvas3d, Font font, MutableText2D text2D, Transform3D translateTextT3D, float depth, float scaleFactor)
	{
		if(text2D.getString() == null)
			return;
		
		Rectangle2D stringBounds = canvas3d.getFontMetrics(font).
			getStringBounds(text2D.getString(), canvas3d.getGraphics());
		
		float textMoveLeftShift = ((float)stringBounds.getWidth() * text2D.getRectangleScaleFactor()) / 2.0f;
		float textMoveDownShift = (float)(((double)stringBounds.getHeight()) * text2D.getRectangleScaleFactor()  / 2.0);
		
		translateTextT3D.set(new Vector3d( -textMoveLeftShift * scaleFactor, -textMoveDownShift * scaleFactor, depth + 0.01 ));
//		translateTextTrnsGrp.setTransform(translateTextT3D);
	}
	
	
	public static void prepareLeftAlignedText2DTransform(Canvas3D canvas3d, Font font, MutableText2D text2D, Transform3D translateTextT3D, float leftBorder, float depth, float scaleFactor)
	{
		if(text2D.getString() == null)
			return;
		
		Rectangle2D stringBounds = canvas3d.getFontMetrics(font).
			getStringBounds(text2D.getString(), canvas3d.getGraphics());
		
//		float textMoveLeftShift = ((float)stringBounds.getWidth() * text2D.getRectangleScaleFactor()) / 2.0f;
		float textMoveDownShift = (float)(((double)stringBounds.getHeight()) * text2D.getRectangleScaleFactor()  / 2.0);
		
		translateTextT3D.set(new Vector3d( -leftBorder, -textMoveDownShift* scaleFactor , depth + 0.01 ));
//		translateTextTrnsGrp.setTransform(translateTextT3D);
	}
	
}
